<template>
<div>
  <h1>管理员审核</h1>
  <el-table :data="tableData" style="width: 100%" >
    <el-table-column prop="goodsId" label="商品编号" width="180"></el-table-column>
    <el-table-column prop="goodsName" label="商品名称" width="180"></el-table-column>
    <el-table-column prop="goodsStock" label="商品库存" width="180"></el-table-column>
    <el-table-column prop="goodsState" label="商品状态" width="180">
      <template slot-scope="scope">
        {{flag[scope.row.goodsState]}}
        <el-button size="mini" @click="handleEdit(scope.row.goodsId)">审核</el-button>
      </template>
    </el-table-column>
<!--    <el-table-column prop="goodsQuantity" label="日期" width="180"></el-table-column>-->
    <el-table-column prop="goodsUpdatetime" label="商品日期" width="180"></el-table-column>
    <!--    <el-table-column prop="deleted" label="日期" width="180"></el-table-column>-->
    <el-table-column prop="createTime" label="创建日期" width="180"></el-table-column>
    <el-table-column prop="updateTime" label="最后修改日期" width="180"></el-table-column>
    <el-table-column prop="storeId" label="商家编号" width="180"></el-table-column>
  </el-table>
  <div class="block">
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="goodslist.page"
      :page-sizes="[1, 3, 6, 9]"
      :page-size="goodslist.size"
      layout="total, sizes, prev, pager, next, jumper"
      :total="goodslist.total">
    </el-pagination>
  </div>



  <el-dialog title="审核状态" :visible.sync="dialogFormVisible">
    <el-form :model="goodslist">
      <el-form-item label="状态">
        <el-select v-model="goodslist.goodsState" placeholder="状态">
          <el-option label="待审核" value="0"></el-option>
          <el-option label="审核通过" value="1"></el-option>
          <el-option label="审核不通过" value="2"></el-option>
          <el-option label="上架" value="3"></el-option>
          <el-option label="下架" value="4"></el-option>
        </el-select>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="dialogFormVisible = false">取 消</el-button>
      <el-button type="primary" @click="addQuestion">确 定</el-button>
    </div>
  </el-dialog>
</div>
</template>

<script>
    import axios from "axios";
    export default {
        name: "index",
      data(){
        return{
          tableData:[],
          goodslist:{page:1,size:3,total:0},
          flag:['待审核','审核通过','审核不通过','已上架','已下架'],
          dialogFormVisible: false,
          formLabelWidth: '120px',
          storeId:'',
        }
      },
      methods:{
        getlist(){
          let userId= sessionStorage.getItem("userId")
          console.log(userId)
          let userRole= sessionStorage.getItem("userRole")
          console.log(userRole)
          let storeId= sessionStorage.getItem("storeId")
          var us= new FormData();
          us.append("page",this.goodslist.page)
          us.append("size",this.goodslist.size)
          us.append("total",this.goodslist.total)
          us.append("storeId",storeId)
          us.append("userId",userId)
          us.append("userRole",userRole)
          axios.post("http://localhost:7000/shop/store/adminlist",us,this.goodslist).then(res=>{
            console.log(res)
            this.goodslist.total=res.data.data.total
            this.tableData=res.data.data.records
          })
        },
        handleSizeChange(val) {
          this.goodslist.size=val
          console.log(`每页 ${val} 条`);
          this.getlist()
        },
        handleCurrentChange(val) {
          this.goodslist.page=val
          console.log(`当前页: ${val}`);
          this.getlist()
        },
        handleEdit(goodsId){
          this.goodsId=goodsId
          console.log(goodsId)
          this.dialogFormVisible=true
        },
        addQuestion(){
          this.dialogFormVisible = false
          axios.post("http://localhost:7000/shop/store/updategoods?goodsId="+this.goodsId,this.goodslist).then((res) => {
            this.dialogFormVisible = false
            this.getlist()
            console.log(res)
          })
        }
      },
      mounted() {
        this.getlist()
      }
    }
</script>

<style scoped>

</style>
